/*
 * Copyright (c) 2010-2011 NOO. All Rights Reserved.
 * [Id:ModuleBean.java  2011-11-05 下午5:26 poplar.yfyang ]
 */
package org.mumu.pawn.beans.bam;

import org.mumu.pawn.cmps.ModuleCmp;
import org.mumu.pawn.cmps.OperateCmp;
import org.mumu.pawn.domain.Module;
import org.mumu.pawn.domain.Operate;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * Module ManagerBean.
 * </p>
 *
 * @author poplar.yfyang
 * @version 1.0 2011-11-05 下午5:26
 * @since JDK 1.5
 */
@Named
@ViewScoped
public class ModuleBean implements Serializable {
    private static final long serialVersionUID = 6426169143141089790L;
    /**
     * Module list
     */
    private List<Module> moduleList;

    /**
     * Module Init
     */
    @PostConstruct
    protected void init() {
        moduleList = moduleCmp.getModuleList();
    }

    private String url;

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public void popupModuleAdd() {
        operate = new Operate();
        module = new Module();
        url="module/moduleEntity.xhtml";
    }

    public void popupModuleEdit() {
        operate = new Operate();
        url = "module/moduleEntity.xhtml";
    }

    public void popupAddOperate() {
        operate = new Operate();
        url = "module/operateEntity.xhtml";
    }

    public void remove(){
        operateCmp.deleteOperate(operate.getId());
    }

    public void removeModule(){
        moduleCmp.removeModule(module.getId());
    }


    public void saveModule(){
        moduleCmp.saveOrUpdateModule(module);
    }

    public void saveOperate(){
        operateCmp.saveOrUpdateOperate(operate);
    }


    public List<Module> getModuleList() {
        return moduleList;
    }

    public Operate getOperate() {
        return operate;
    }

    public void setOperate(Operate operate) {
        this.operate = operate;
    }

    public Module getModule() {
        return module;
    }

    public void setModule(Module module) {
        this.module = module;
    }

    private Operate operate = new Operate();

    private Module module = new Module();



    @Inject
    private ModuleCmp moduleCmp;
    @Inject
    private OperateCmp operateCmp;
}
